<?php

namespace backend\modules\business\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\business\BusinessPigFile;

/**
 * BusinessPigFileSearch represents the model behind the search form about `common\models\business\BusinessPigFile`.
 */
class BusinessPigFileSearch extends BusinessPigFile
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'variety', 'constract_id'], 'integer'],
            [['name', 'no', 'father', 'mathor', 'matherphoto', 'fatherphoto'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = BusinessPigFile::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'variety' => $this->variety,
            'constract_id' => $this->constract_id,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'no', $this->no])
            ->andFilterWhere(['like', 'father', $this->father])
            ->andFilterWhere(['like', 'mathor', $this->mathor])
            ->andFilterWhere(['like', 'matherphoto', $this->matherphoto])
            ->andFilterWhere(['like', 'fatherphoto', $this->fatherphoto]);

        return $dataProvider;
    }
}
